package org.example.sunrise.utils;

import javafx.scene.image.Image;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class ImageUtil {
    private static final Map<String, Image> cache = new HashMap<>();

    public static Image createImage(String path, double width, double height, Class<?> clazz) {
        String key = path + width + height;
        if (cache.containsKey(key)) {
            return cache.get(key);
        } else {
            Image img = new Image(Objects.requireNonNull(clazz.getResource(path)).toString(), width, height, false, false);
            cache.put(key, img);
            return img;
        }
    }
}
